<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Send/SendRaw/SendInput/SendPlay/SendEvent: Send keys &amp; clicks</title>
<meta name="description" content="Send keystrokes and mouse clicks to any window with this free macro program. SendInput is generally the fastest and most reliable method.">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<style type="text/css">
<!--
.red {color: #FF0000; font-weight: bold;}
-->
</style>
</head>
<body>

<h1>Send / SendRaw / SendInput / SendPlay / SendEvent: Send Keys &amp; Clicks</h1>

<p>Sends simulated keystrokes and mouse clicks to the <a href="WinActivate.htm">active</a> window.</p>

<pre class="Syntax">Send Keys
SendRaw Keys
SendInput Keys
SendPlay Keys
SendEvent Keys</pre>
<h3>Parameters</h3>
<dl>

  <dt>Keys</dt>
  <dd><p>The sequence of keys to send. As with other commands, the comma in front of the first parameter is optional.</p></dd>

</dl>

<p><strong><a name="SendRaw"></a>Raw mode</strong>: The <em>SendRaw</em> command interprets all characters literally rather than translating {Enter} to an ENTER keystroke, ^c to Control-C, etc. However, the normal rules for escape sequences, variable references and expressions still apply since these are processed before the command executes. To use raw mode with SendInput, SendPlay, or SendEvent, write <a href="#Raw">{Raw}</a> as the first item in the string; for example: <code>SendInput {Raw}abc</code>.</p>
<p><strong>Normal mode</strong>: When not in raw mode, the following characters are treated as modifiers (these modifiers affect only the very next key):</p>
<p><span class="red">!</span>: Sends an ALT keystroke. For example, <code>Send This is text!a</code> would send the keys &quot;This is text&quot; and then press ALT+a. <strong>Note</strong>: !A produces a different effect in some programs than !a. This is because !A presses ALT+SHIFT+A and !a presses ALT+a. If in doubt, use lowercase.</p>
<p><span class="red">+</span>: Sends a SHIFT keystroke. For example, <code>Send +abC</code> would send the text &quot;AbC&quot;, and <code>Send !+a</code> would press ALT+SHIFT+a.</p>
<p><span class="red">^</span>: Sends a CONTROL keystroke. For example, <code>Send ^!a</code> would press CTRL+ALT+a, and <code>Send ^{Home}</code> would send CONTROL+HOME. <strong>Note</strong>: ^A produces a different effect in some programs than ^a. This is because ^A presses CONTROL+SHIFT+A and ^a presses CONTROL+a. If in doubt, use lowercase.</p>
<p><span class="red">#</span>: Sends a WIN keystroke, therefore <code>Send #e</code> would hold down the Windows key and then press the letter &quot;e&quot;.</p>
<p><br>
<a name="SendInput"></a><a name="SendPlay"></a><strong>SendInput</strong> and <strong>SendPlay</strong> <span class="ver">[v1.0.43+]:</span> SendInput and SendPlay use the same syntax as Send but are generally faster and more reliable. In addition, they buffer any physical keyboard or mouse activity during the send, which prevents the user's keystrokes from being interspersed with those being sent. <a href="SendMode.htm">SendMode</a> can be used to make Send synonymous with SendInput or SendPlay. For more details about each mode, see <a href="#SendInputDetail">SendInput</a> and <a href="#SendPlayDetail">SendPlay</a> below.</p>
<p><a name="SendEvent"></a><strong>SendEvent</strong> <span class="ver">[v1.0.43+]:</span> SendEvent sends keystrokes using the same method as the pre-1.0.43 <em>Send</em> command. The rate at which keystrokes are sent is determined by <a href="SetKeyDelay.htm">SetKeyDelay</a>. By default, <em>Send</em> is synonymous <em>SendEvent</em>; but it can be made a synonym for <a href="#SendInputDetail">SendInput</a> or <a href="#SendPlayDetail">SendPlay</a> via <a href="SendMode.htm">SendMode</a>.</p>
<p><strong>Key Names</strong>: The following table lists the special keys that can be sent (each key name must be enclosed in braces):</p>
<table class="info">
  <tr>
    <th width="200">Key Name</th>
    <th>Resulting Keystroke</th>
  </tr>
  <tr>
    <td align="center">{F1} - {F24}</td>
    <td>Function keys. For example: {F12} is the F12 key.</td>
  </tr>
  <tr>
    <td align="center">{!}</td>
    <td>!</td>
  </tr>
  <tr>
    <td align="center">{#}</td>
    <td>#</td>
  </tr>
  <tr>
    <td align="center">{+}</td>
    <td>+</td>
  </tr>
  <tr>
    <td align="center">{^}</td>
    <td>^</td>
  </tr>
  <tr>
    <td align="center">{{}</td>
    <td>{</td>
  </tr>
  <tr>
    <td align="center">{}}</td>
    <td>}</td>
  </tr>
  <tr>
    <td align="center">{Enter}</td>
    <td>ENTER key on the main keyboard</td>
  </tr>
  <tr>
    <td align="center">{Escape} or {Esc}</td>
    <td>ESCAPE</td>
  </tr>
  <tr>
    <td align="center">{Space}</td>
    <td>SPACE (this is only needed for spaces that appear either at the beginning or the end of the string to be sent -- ones in the middle can be literal spaces)</td>
  </tr>
  <tr>
    <td align="center">{Tab}</td>
    <td>TAB</td>
  </tr>
  <tr>
    <td align="center">{Backspace} or {BS}</td>
    <td>Backspace</td>
  </tr>
  <tr>
    <td align="center">{Delete} or {Del}</td>
    <td>Delete</td>
  </tr>
  <tr>
    <td align="center">{Insert} or {Ins}</td>
    <td>Insert</td>
  </tr>
  <tr>
    <td align="center">{Up}</td>
    <td>Up-arrow key on main keyboard</td>
  </tr>
  <tr>
    <td align="center">{Down}</td>
    <td>Down-arrow down key on main keyboard</td>
  </tr>
  <tr>
    <td align="center">{Left}</td>
    <td>Left-arrow key on main keyboard</td>
  </tr>
  <tr>
    <td align="center">{Right}</td>
    <td>Right-arrow key on main keyboard</td>
  </tr>
  <tr>
    <td align="center">{Home}</td>
    <td>Home key on main keyboard</td>
  </tr>
  <tr>
    <td align="center">{End}</td>
    <td>End key on main keyboard</td>
  </tr>
  <tr>
    <td align="center">{PgUp}</td>
    <td>Page-up  key on main keyboard</td>
  </tr>
  <tr>
    <td align="center">{PgDn}</td>
    <td>Page-down  key on main keyboard</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{CapsLock}</td>
    <td>CapsLock (using <a href="SetNumScrollCapsLockState.htm">SetCapsLockState</a> is more reliable on Win 2k/XP).


 Sending {CapsLock} might require <a href="SetStoreCapslockMode.htm">SetStoreCapslockMode Off</a> beforehand.</td>
  </tr>
  <tr>
    <td align="center">{ScrollLock}</td>
    <td>ScrollLock (see also: <a href="SetNumScrollCapsLockState.htm">SetScrollLockState</a>)</td>
  </tr>
  <tr>
    <td align="center">{NumLock}</td>
    <td>NumLock (see also: <a href="SetNumScrollCapsLockState.htm">SetNumLockState</a>)</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{Control} or {Ctrl}</td>
    <td>CONTROL (technical info: sends the neutral virtual key but the left scan code)</td>
  </tr>
  <tr>
    <td align="center">{LControl} or {LCtrl}</td>
    <td>Left CONTROL key (technical info: sends the left virtual key rather than the neutral one)</td>
  </tr>
  <tr>
    <td align="center">{RControl} or {RCtrl}</td>
    <td>Right CONTROL key</td>
  </tr>
  <tr>
    <td align="center">{Control Down} or {Ctrl Down}</td>
    <td>Holds the CONTROL key down until {Ctrl Up} is sent. To hold down the left or right key instead, use {RCtrl Down} and {RCtrl Up}.</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{Alt}</td>
    <td>ALT (technical info: sends the neutral virtual key but the left scan code)</td>
  </tr>
  <tr>
    <td align="center">{LAlt}</td>
    <td>Left ALT key (technical info: sends the left virtual key rather than the neutral one)</td>
  </tr>
  <tr>
    <td align="center">{RAlt}</td>
    <td>Right ALT key (or AltGr, depending on keyboard layout)</td>
  </tr>
  <tr>
    <td align="center">{Alt Down}</td>
    <td>Holds the ALT key down until {Alt Up} is sent. To hold down the left or right key instead, use {RAlt Down} and {RAlt Up}.</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{Shift}</td>
    <td>SHIFT (technical info: sends the neutral virtual key but the left scan code)</td>
  </tr>
  <tr>
    <td align="center">{LShift}</td>
    <td>Left SHIFT key (technical info: sends the left virtual key rather than the neutral one)</td>
  </tr>
  <tr>
    <td align="center">{RShift}</td>
    <td>Right SHIFT key</td>
  </tr>
  <tr>
    <td align="center">{Shift Down}</td>
    <td>Holds the SHIFT key down until {Shift Up} is sent. To hold down the left or right key instead, use {RShift Down} and {RShift Up}.</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{LWin}</td>
    <td>Left Windows key</td>
  </tr>
  <tr>
    <td align="center">{RWin}</td>
    <td>Right Windows key</td>
  </tr>
  <tr>
    <td align="center">{LWin Down}</td>
    <td>Holds the left Windows key down until {LWin Up} is sent</td>
  </tr>
  <tr>
    <td align="center">{RWin Down}</td>
    <td>Holds the right Windows key down until {RWin Up} is sent</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{AppsKey}</td>
    <td>Windows App key (invokes the right-click or context menu)</td>
  </tr>
  <tr>
    <td align="center">{Sleep}</td>
    <td>Computer SLEEP key.</td>
  </tr>
  <tr>
    <td align="center">{ASC nnnnn}</td>
    <td><p><a name="asc"></a>Sends an ALT+nnnnn keypad combination, which can be used to generate special characters that don't exist on the keyboard. To generate ASCII characters, specify a number between 1 and 255. To generate ANSI characters (standard in most languages), specify a number between 128 and 255, but precede it with a leading zero, e.g. {Asc 0133}.</p>
    <p>Unicode characters may be generated by specifying a number between 256 and 65535 (without a leading zero). However, this is not supported by all applications. For alternatives, see the section below.</p></td>
  </tr>
  <tr id="Unicode">
    <td align="center">{U+nnnn}</td>
    <td><p><a name="sendu"></a><span class="ver">[AHK_L 24+]:</span> Sends a Unicode character where <em>nnnn</em> is the hexadecimal value of the character excluding the 0x prefix. This typically isn't needed in Unicode versions of AutoHotkey, where Send and ControlSend automatically support Unicode text.</p>
    <p>If the character doesn't map to a virtual keycode, <a href="http://msdn.microsoft.com/en-us/library/ms646310.aspx">SendInput()</a> or <a href="http://msdn.microsoft.com/en-us/library/ms646276.aspx">WM_CHAR</a> is used to send the character and the current Send mode has no effect.</p></td>
  </tr>
  <tr>
    <td align="center"><p>{vkXX}<br>
      {scYYY}<br>
    {vkXXscYYY}</p></td>
    <td><p><a name="vk"></a>Sends a keystroke that has virtual key XX and scan code YYY. For example: <code>Send {vkFFsc159}</code>. If the sc or vk portion is omitted, the most appropriate value is sent in its place.</p>
      <p>The values for XX and YYY are hexadecimal and can usually be determined from the main window's <a href="KeyHistory.htm">View-&gt;Key history</a> menu item. See also: <a href="../KeyList.htm#SpecialKeys">Special Keys</a></p></td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{Numpad0} - {Numpad9}</td>
    <td>Numpad digit keys (as seen when Numlock is ON). For example: {Numpad5} is the digit 5.</td>
  </tr>
  <tr>
    <td align="center">{NumpadDot}</td>
    <td>Numpad Period (as seen when Numlock is ON).</td>
  </tr>
  <tr>
    <td align="center">{NumpadEnter}</td>
    <td>Enter key on keypad</td>
  </tr>
  <tr>
    <td align="center">{NumpadMult}</td>
    <td>Numpad Multiply</td>
  </tr>
  <tr>
    <td align="center">{NumpadDiv}</td>
    <td>Numpad Divide</td>
  </tr>
  <tr>
    <td align="center">{NumpadAdd}</td>
    <td>Numpad Add</td>
  </tr>
  <tr>
    <td align="center">{NumpadSub}</td>
    <td>Numpad Subtract</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{NumpadDel}</td>
    <td>Delete key on keypad (this key and the following Numpad keys are used when Numlock is OFF)</td>
  </tr>
  <tr>
    <td align="center">{NumpadIns}</td>
    <td>Insert key on keypad</td>
  </tr>
  <tr>
    <td align="center">{NumpadClear}</td>
    <td>Clear key on keypad (usually the '5' key when Numlock is OFF).</td>
  </tr>
  <tr>
    <td align="center">{NumpadUp}</td>
    <td>Up-arrow key on keypad</td>
  </tr>
  <tr>
    <td align="center">{NumpadDown}</td>
    <td>Down-arrow key on keypad</td>
  </tr>
  <tr>
    <td align="center">{NumpadLeft}</td>
    <td>Left-arrow key on keypad</td>
  </tr>
  <tr>
    <td align="center">{NumpadRight}</td>
    <td>Right-arrow key on keypad</td>
  </tr>
  <tr>
    <td align="center">{NumpadHome}</td>
    <td>Home key on keypad</td>
  </tr>
  <tr>
    <td align="center">{NumpadEnd}</td>
    <td>End key on keypad</td>
  </tr>
  <tr>
    <td align="center">{NumpadPgUp}</td>
    <td>Page-up key on keypad</td>
  </tr>
  <tr>
    <td align="center">{NumpadPgDn}</td>
    <td>Page-down key on keypad</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{Browser_Back}</td>
    <td>Select the browser &quot;back&quot; button</td>
  </tr>
  <tr>
    <td align="center">{Browser_Forward}</td>
    <td>Select the browser &quot;forward&quot; button</td>
  </tr>
  <tr>
    <td align="center">{Browser_Refresh}</td>
    <td>Select the browser &quot;refresh&quot; button</td>
  </tr>
  <tr>
    <td align="center">{Browser_Stop}</td>
    <td>Select the browser &quot;stop&quot; button</td>
  </tr>
  <tr>
    <td align="center">{Browser_Search}</td>
    <td>Select the browser &quot;search&quot; button</td>
  </tr>
  <tr>
    <td align="center">{Browser_Favorites}</td>
    <td>Select the browser &quot;favorites&quot; button</td>
  </tr>
  <tr>
    <td align="center">{Browser_Home}</td>
    <td>Launch the browser and go to the home page</td>
  </tr>
  <tr>
    <td align="center">{Volume_Mute}</td>
    <td>Mute/unmute the master volume. Usually equivalent to <code><a href="SoundSet.htm">SoundSet</a>, +1, , mute</code>.</td>
  </tr>
  <tr>
    <td align="center">{Volume_Down}</td>
    <td>Reduce the master volume. Usually equivalent to <code><a href="SoundSet.htm">SoundSet</a> -5</code>.</td>
  </tr>
  <tr>
    <td align="center">{Volume_Up}</td>
    <td>Increase the master volume. Usually equivalent to <code><a href="SoundSet.htm">SoundSet</a> +5</code>.</td>
  </tr>
  <tr>
    <td align="center">{Media_Next}</td>
    <td>Select next track in media player</td>
  </tr>
  <tr>
    <td align="center">{Media_Prev}</td>
    <td>Select previous track in media player</td>
  </tr>
  <tr>
    <td align="center">{Media_Stop}</td>
    <td>Stop media player</td>
  </tr>
  <tr>
    <td align="center">{Media_Play_Pause}</td>
    <td>Play/pause media player</td>
  </tr>
  <tr>
    <td align="center">{Launch_Mail}</td>
    <td>Launch the email application</td>
  </tr>
  <tr>
    <td align="center">{Launch_Media}</td>
    <td>Launch media player</td>
  </tr>
  <tr>
    <td align="center">{Launch_App1}</td>
    <td>Launch user app1</td>
  </tr>
  <tr>
    <td align="center">{Launch_App2}</td>
    <td>Launch user app2</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center">{PrintScreen}</td>
    <td>Print Screen</td>
  </tr>
  <tr>
    <td align="center">{CtrlBreak}</td>
    <td>Ctrl+break</td>
  </tr>
  <tr>
    <td align="center">{Pause}</td>
    <td>Pause</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td align="center"><strong>{Click [Options]}</strong><br>
    <span class="ver">[v1.0.43+]</span></td>
    <td><a name="Click"></a>Sends a mouse click using the same options available in the <a href="Click.htm">Click command</a>. For example, <code>{Click}</code> would click the left mouse button once at the mouse cursor's current position, and <code>{Click 100, 200}</code> would click at coordinates 100, 200 (based on <a href="CoordMode.htm">CoordMode</a>). To move the mouse without clicking, specify 0 after the coordinates; for example: <code>{Click 100, 200, 0}</code>. The delay between mouse clicks is determined by <a href="SetMouseDelay.htm">SetMouseDelay</a> (not <a href="SetKeyDelay.htm">SetKeyDelay</a>).</td>
  </tr>
  <tr>
    <td align="center">{WheelDown}, {WheelUp}, {WheelLeft}, {WheelRight}, {LButton}, {RButton}, {MButton}, {XButton1}, {XButton2}</td>
    <td>Sends a mouse button event at the cursor's current position (to have control over position and other options, use <a href="Click.htm">{Click}</a> above). The delay between mouse clicks is determined by <a href="SetMouseDelay.htm">SetMouseDelay</a>. WheelLeft/Right require v1.0.48+, but have no effect on operating systems older than Windows Vista.</td>
  </tr>
  <tr>
    <td align="center"><strong>{Blind}</strong></td>
    <td><p><a name="blind"></a>When {Blind} is the first item in the string, the program avoids releasing Alt/Control/Shift/Win if they started out in the down position. For example, the hotkey <code>+s::Send {Blind}abc</code> would send ABC rather than abc because the user is holding down the Shift key.</p>
      <p>{Blind} also causes <a href="SetStoreCapslockMode.htm">SetStoreCapslockMode</a> to be ignored; that is, the state of Capslock is not changed. Finally, {Blind} omits the extra Control keystrokes that would otherwise be sent; such keystrokes prevent: 1) Start Menu appearance during LWin/RWin keystrokes; 2) menu bar activation during Alt keystrokes.</p>
      <p>Blind-mode is used internally when <a href="../misc/Remap.htm">remapping a key</a>. For example, the remapping a::b would produce: 1) &quot;b&quot; when you type &quot;a&quot;; 2) uppercase B when you type uppercase A; and 3) Control-B when you type Control-A.</p>
      <p>{Blind} is not supported by SendRaw and <a href="ControlSend.htm">ControlSendRaw</a>. Furthermore, it is not completely supported by <a href="#SendPlayDetail">SendPlay</a>, especially when dealing with the modifier keys (Control, Alt, Shift, and Win).</p></td>
  </tr>
  <tr>
    <td align="center"><strong>{Raw}</strong><br>
    <span class="ver">[v1.0.43+]</span></td>
    <td><a name="Raw" id="Raw"></a>Sends the keystrokes exactly as they appear rather than translating {Enter} to an ENTER keystroke, <code>^c</code> to Control-C, etc. Although the string {Raw} need not occur at the beginning of the string, once specified, it stays in effect for the remainder of the string.</td>
  </tr>
</table>

<h2>Repeating  or Holding Down a Key</h2>
<p><strong>To repeat a keystroke</strong>: Enclose in braces the name of the key followed by the number of times to repeat it. For example:</p>
<pre>Send {DEL 4}  <em>; Presses the Delete key 4 times.</em>
Send {S 30}   <em>; Sends 30 uppercase S characters.</em>
Send +{TAB 4}  <em>; Presses Shift-Tab 4 times.</em></pre>
<p><strong>To hold down or release a key</strong>: Enclose in braces the name of the key followed by the word <strong>Down</strong> or <strong>Up</strong>. For example:</p>
<pre>Send {b down}{b up}
Send {TAB down}{TAB up}
Send {Up down}  <em>; Press down the up-arrow key.</em>
Sleep 1000  <em>; Keep it down for one second.</em>
Send {Up up}  <em>; Release the up-arrow key.</em></pre>
<p>When a key is held down via the method above, it does not begin auto-repeating like it would if you were physically holding it down (this is because auto-repeat is a driver/hardware feature). However, a <a href="Loop.htm">Loop</a> can be used to simulate auto-repeat. The following example sends 20 tab keystrokes:</p>
<pre>Loop 20
{
    Send {Tab down}  <em>; Auto-repeat consists of consecutive down-events (with no up-events).</em>
    Sleep 30  <em>; The number of milliseconds between keystrokes (or use <a href="SetKeyDelay.htm">SetKeyDelay</a>).</em>
}
Send {Tab up}  <em>; Release the key.</em></pre>
<p>The word <em>DownTemp</em> may also be used. Its effect is the same as <em>Down</em> except for the modifer keys (Control/Shift/Alt/Win). In those cases, <em>DownTemp</em> tells subsequent sends that the key is not permanently down, and may be released whenever a keystroke calls for it. For example, <code>Send {Control DownTemp}</code> followed later by <code>Send a</code> would produce a normal &quot;a&quot; keystroke, not a control-A keystroke.</p>

<h2 id="Remarks">General Remarks</h2>
<p>There are no specific limitations on which characters the Send command supports. If a character does not exist in the current keyboard layout, it is simulated by sending a Unicode character packet or <a href="#asc">Alt+nnnnn</a> combination, depending on the version of AutoHotkey. Unicode characters are supported directly as text in Unicode versions of AutoHotkey, or using <a href="#sendu">{U+nnnn} notation</a> in any version.</p>
<p><strong>BlockInput Compared to SendInput/SendPlay</strong>: Although the <a href="BlockInput.htm">BlockInput</a> command can be used to prevent any keystrokes physically typed by the user from disrupting the flow of simulated keystrokes, it is often better to use <a href="#SendInputDetail">SendInput</a> or <a href="#SendPlayDetail">SendPlay</a> so that keystrokes and mouse clicks become uninterruptible. This is because unlike BlockInput, SendInput/Play does not discard what the user types during the send; instead, such keystrokes are buffered and sent afterward.</p>
<p>When sending a large number of keystrokes, a <a href="../Scripts.htm#continuation">continuation section</a> can be used to improve readability and maintainability.</p>
<p>Since the operating system does not allow simulation of the CTRL-ALT-DELETE combination, doing something like <code>Send ^!{Delete}</code> will have no effect.</p>
<p><b>Send may have no effect</b> on Windows Vista or later if the active window is running with administrative privileges and the script is not. This is due to a security mechanism called User Interface Privilege Isolation.</p>

<h2 id="SendInputDetail">SendInput <span class="ver">[v1.0.43+]</span></h2>
<p>SendInput is generally the preferred method to send keystrokes and mouse clicks because of its superior speed and reliability. Under most conditions, SendInput is nearly instantaneous, even when sending long strings. Since SendInput is so fast, it is also more reliable because there is less opportunity for some other window to pop up unexpectedly and intercept the keystrokes. Reliability is further improved by the fact that anything the user types during a SendInput is postponed until afterward.</p>
<p>Unlike the other sending modes, the operating system limits SendInput to about 5000 characters (this may vary depending on the operating system's version and performance settings). Characters and events beyond this limit are not sent.</p>
<p><strong>Note:</strong> SendInput ignores SetKeyDelay because the operating system does not support a delay in this mode. However, when SendInput reverts to <a href="#SendEvent">SendEvent</a> under the conditions described below, it uses <code><a href="SetKeyDelay.htm">SetKeyDelay -1, 0</a></code> (unless SendEvent's KeyDelay is <code>-1,-1</code>, in which case <code>-1,-1</code> is used). When SendInput reverts to <a href="#SendPlayDetail">SendPlay</a>, it uses SendPlay's KeyDelay.</p>
<p><a name="SendInputUnavail"></a>If a script <em>other than</em> the one executing SendInput has a <a href="_InstallKeybdHook.htm">low-level keyboard hook</a> installed, SendInput automatically reverts to <a href="#SendEvent">SendEvent</a> (or <a href="#SendPlayDetail">SendPlay</a> if <a href="SendMode.htm"><code>SendMode InputThenPlay</code></a> is in effect). This is done because the presence of an external hook disables all of SendInput's advantages, making it inferior to both SendPlay and SendEvent. However, since SendInput is unable to detect a low-level hook in programs other than AutoHotkey v1.0.43+, it will not revert in these cases, making it less reliable than SendPlay/Event.</p>
<p>When SendInput sends mouse clicks by means such as <a href="#Click">{Click}</a>, and <a href="SetMouseDelay.htm"><code>CoordMode Mouse, Relative</code></a> is in effect (the default), every click will be relative to the window that was active at the start of the send. Therefore, if SendInput intentionally activates another window (by means such as alt-tab), the coordinates of subsequent clicks within the same command will be wrong because they will still be relative to the old window rather than the new one.</p>
<h2 id="SendPlayDetail">SendPlay <span class="ver">[v1.0.43+]</span></h2>
<p>SendPlay's biggest advantage is its ability to &quot;play back&quot; keystrokes and mouse clicks in a broader variety of games than the other modes. For example, a particular game may accept <a href="../Hotstrings.htm#SendMode">hotstrings</a> only when they have the <a href="../Hotstrings.htm#SendMode">SendPlay option</a>. However, SendPlay may have no effect at all on Windows Vista or later if User Account Control is enabled, even if the script is running as an administrator. The following script provides a workaround for this problem: <a href="http://www.autohotkey.com/forum/topic75595.html">http://www.autohotkey.com/forum/topic75595.html</a>.</p>
<p>Of the three sending modes, SendPlay is the most unusual because it does not simulate keystrokes and mouse clicks per se. Instead, it creates a series of events (messages) that flow directly to the active window (similar to <a href="ControlSend.htm">ControlSend</a>, but at a lower level). Consequently, SendPlay does not trigger hotkeys or hotstrings.</p>
<p>Like <a href="#SendInputDetail">SendInput</a>, SendPlay's keystrokes do not get interspersed with keystrokes typed by the user. Thus, if the user happens to type something during a SendPlay, those keystrokes are postponed until afterward.</p>
<p>Although SendPlay is considerably slower than SendInput, it is usually faster than the traditional <a href="#SendEvent">SendEvent</a> mode (even when <a href="SetKeyDelay.htm">KeyDelay</a> is -1).</p>
<p>The Windows keys (LWin and RWin) are automatically blocked during a SendPlay if the <a href="_InstallKeybdHook.htm">keyboard hook</a> is installed. This prevents the Start Menu from appearing if the user accidentally presses a Windows key during the send. By contrast, keys other than LWin and RWin do not need to be blocked because the operating system automatically postpones them until after the SendPlay (via buffering).</p>
<p>SendPlay does not use the standard settings of SetKeyDelay and SetMouseDelay. Instead, it defaults to no delay at all, which can be changed as shown in the following examples:</p>
<pre><a href="SetKeyDelay.htm">SetKeyDelay</a>, 0, 10, <strong>Play</strong>  <em>; Note that both 0 and -1 are the same in SendPlay mode.</em>
<a href="SetMouseDelay.htm">SetMouseDelay</a>, 10, <strong>Play</strong></pre>
<p>SendPlay is unable to turn on or off the Capslock, Numlock, or Scroll-lock keys. Similarly, it is unable to change a key's state as seen by <a href="GetKeyState.htm">GetKeyState</a> unless the keystrokes are sent to one of the script's own windows. Even then, any changes to the left/right modifier keys (e.g. RControl) can be detected only via their neutral counterparts (e.g. Control). Also, SendPlay has other limitations described on the <a href="SendMode.htm#Play">SendMode page</a>.</p>
<p>Unlike <a href="#SendInputDetail">SendInput</a> and <a href="#SendEvent">SendEvent</a>, the user may interrupt a SendPlay by pressing Control-Alt-Del or Control-Escape. When this happens, the remaining keystrokes are not sent but the script continues executing as though the SendPlay had completed normally.</p>
<p>Although SendPlay can send LWin and RWin events, they are sent directly to the active window rather than performing their native operating system function. To work around this, use <a href="#SendEvent">SendEvent</a>. For example, <code>SendEvent #r</code> would show the Start Menu's Run dialog.</p>

<h2>Related</h2>
<p><a href="SendMode.htm">SendMode</a>, <a href="SetKeyDelay.htm">SetKeyDelay</a>, <a href="SetStoreCapslockMode.htm">SetStoreCapslockMode</a>, <a href="_EscapeChar.htm">Escape sequences (e.g. `%)</a>, <a href="ControlSend.htm">ControlSend</a>, <a href="BlockInput.htm">BlockInput</a>, <a href="../Hotstrings.htm">Hotstrings</a>, <a href="WinActivate.htm">WinActivate</a></p>
<h2>Examples</h2>
<pre class="NoIndent">Send Sincerely,{enter}John Smith  <em>; Types a two-line signature.</em>
Send !fs <em>; Select the File-&gt;Save menu (Alt+F followed by S).</em>
Send {End}+{Left 4} <em>; Jump to the end of the text then send four shift+left-arrow keystrokes.</em>
SendInput <a href="#Raw">{Raw}</a>A long series of raw characters sent via the fastest method (<a href="#SendInputDetail">SendInput</a>).</pre>

</body>
</html>
